package com.cjm.jvmcollectors;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CjmArrayList {
    public static void main(String[] args) {
        List<String> sentences = Arrays.asList("hello world","Jia Gou Wu Dao");
        // 演示点1： 仅peek操作，最终不会执行
        System.out.println("----before peek----");
        sentences.stream().peek(sentence -> System.out.println(sentence));
        System.out.println("----after peek----");
        // 演示点2： 仅foreach操作，最终会执行
        System.out.println("----before foreach----");
        sentences.stream().forEach(sentence -> System.out.println(sentence));
        System.out.println("----after foreach----");
        // 演示点3： peek操作后面增加终止操作，peek会执行
        System.out.println("----before peek and count----");
        sentences.stream().peek(sentence -> System.out.println(sentence)).count();
        System.out.println("----after peek and count----");
    }
    public static void stringToIntFlatmap() {
        List<String> collect = Arrays.asList("hello world", "Jia Gou Wu Dao").stream()
                .flatMap(sentence ->
                        Arrays.stream(sentence.split(" "))
                ).collect(Collectors.toList());
        System.err.println("OK");
    }
    public static void stringToIntMap() {
        List<Integer> collect = Arrays.asList("205", "105", "308", "469", "627").stream()
                .map(id -> {
                    return Integer.parseInt(id) + 100;
                }).collect(Collectors.toList());
        System.err.println("OK");
    }

    private static void extracted() {
        List<String> arrayList = new ArrayList<>(11);
        arrayList.add("a");
        arrayList.add("b");
        arrayList.add("c");
        arrayList.add("d");
        arrayList.add("e");
        arrayList.add("f");
        arrayList.add(2, "A");

        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("a");
        linkedList.add(1, "b");
        linkedList.addFirst("e");
        linkedList.addLast("f");

        linkedList.offer("b");
        linkedList.offerFirst("c");
        linkedList.offerLast("d");

        String peek = linkedList.peek();
        String s = linkedList.peekFirst();
        String s1 = linkedList.peekLast();

        String pop = linkedList.pop();
        linkedList.push("c");
        String remove = linkedList.remove();
    }
}
